#include "DCT.h"


DCT::DCT(int columnLength)
{
	_DCTMatrix = Matrix(columnLength);
	_tDCTMatrix = Matrix(columnLength);
	initDCTMatrices();
}


DCT::~DCT(void)
{
}

void DCT::initDCTMatrices()
{
	double dct[16];
	double tdct[16];

	dct[ 0] =  0.5;
	dct[ 1] =  0.5;
	dct[ 2] =  0.5;
	dct[ 3] =  0.5;
	dct[ 4] =  0.653;
	dct[ 5] =  0.271;
	dct[ 6] = -0.271;
	dct[ 7] = -0.653;
	dct[ 8] =  0.5;
	dct[ 9] = -0.5;
	dct[10] = -0.5;
	dct[11] =  0.5;
	dct[12] =  0.271;
	dct[13] = -0.653;
	dct[14] =  0.653;
	dct[15] = -0.271;

	_DCTMatrix.setMatrixRowMajor(dct);

	tdct[ 0] =  0.5;
	tdct[ 1] =  0.653;
	tdct[ 2] =  0.5;
	tdct[ 3] =  0.271;
	tdct[ 4] =  0.5;
	tdct[ 5] =  0.271;
	tdct[ 6] = -0.5;
	tdct[ 7] = -0.653;
	tdct[ 8] =  0.5;
	tdct[ 9] = -0.271;
	tdct[10] = -0.5;
	tdct[11] =  0.653;
	tdct[12] =  0.5;
	tdct[13] = -0.653;
	tdct[14] =  0.5;
	tdct[15] = -0.271;

	_tDCTMatrix.setMatrixRowMajor(tdct);
}

void DCT::performFDCT(Matrix& m)
{
	Matrix s1 = _DCTMatrix * m;
	Matrix s2 = s1 * _tDCTMatrix;
	m = s2;
	m.round();
}
